<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Irrlicht 3D Engine: Tutorial 20: Managed Lights</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Irrlicht 3D Engine
   
   </div>
   
  </td>
  
  
  
   
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('example020.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Tutorial 20: Managed Lights </div>  </div>
</div>
<div class="contents">
<div class="textblock"><div class="image">
<img src="020shot.jpg" alt="020shot.jpg"/>
</div>
 <p>Written by Colin MacDonald. This tutorial explains the use of the Light Manager of Irrlicht. It enables the use of more dynamic light sources than the actual hardware supports. Further applications of the Light Manager, such as per scene node callbacks, are left out for simplicity of the example. </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>

<span class="keyword">using namespace </span>irr;
<span class="keyword">using namespace </span>core;

<span class="preprocessor">#if defined(_MSC_VER)</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
<span class="preprocessor">#endif // MSC_VER</span>
</pre></div><p>Normally, you are limited to 8 dynamic lights per scene: this is a hardware limit. If you want to use more dynamic lights in your scene, then you can register an optional light manager that allows you to to turn lights on and off at specific point during rendering. You are still limited to 8 lights, but the limit is per scene node.</p>
<p>This is completely optional: if you do not register a light manager, then a default distance-based scheme will be used to prioritise hardware lights based on their distance from the active camera.</p>
<p>NO_MANAGEMENT disables the light manager and shows Irrlicht's default light behaviour. The 8 lights nearest to the camera will be turned on, and other lights will be turned off. In this example, this produces a funky looking but incoherent light display.</p>
<p>LIGHTS_NEAREST_NODE shows an implementation that turns on a limited number of lights per mesh scene node. If finds the 3 lights that are nearest to the node being rendered, and turns them on, turning all other lights off. This works, but as it operates on every light for every node, it does not scale well with many lights. The flickering you can see in this demo is due to the lights swapping their relative positions from the cubes (a deliberate demonstration of the limitations of this technique).</p>
<p>LIGHTS_IN_ZONE shows a technique for turning on lights based on a 'zone'. Each empty scene node is considered to be the parent of a zone. When nodes are rendered, they turn off all lights, then find their parent 'zone' and turn on all lights that are inside that zone, i.e. are descendents of it in the scene graph. This produces true 'local' lighting for each cube in this example. You could use a similar technique to locally light all meshes in (e.g.) a room, without the lights spilling out to other rooms.</p>
<p>This light manager is also an event receiver; this is purely for simplicity in this example, it's neither necessary nor recommended for a real application. </p>
<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CMyLightManager : <span class="keyword">public</span> scene::ILightManager, <span class="keyword">public</span> IEventReceiver
{
    <span class="keyword">typedef</span> <span class="keyword">enum</span>
    {
        NO_MANAGEMENT,
        LIGHTS_NEAREST_NODE,
        LIGHTS_IN_ZONE
    }
    LightManagementMode;

    LightManagementMode Mode;
    LightManagementMode RequestedMode;

    <span class="comment">// These data represent the state information that this light manager</span>
    <span class="comment">// is interested in.</span>
    scene::ISceneManager * SceneManager;
    core::array&lt;scene::ISceneNode*&gt; * SceneLightList;
    <a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> CurrentRenderPass;
    scene::ISceneNode * CurrentSceneNode;

<span class="keyword">public</span>:
    CMyLightManager(scene::ISceneManager* sceneManager)
        : Mode(NO_MANAGEMENT), RequestedMode(NO_MANAGEMENT),
        SceneManager(sceneManager), SceneLightList(0),
        CurrentRenderPass(scene::<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fa1f79a46e7a41716dcae5c8dfe8d310bb" title="No pass currently active.">ESNRP_NONE</a>), CurrentSceneNode(0)
    { }

    <span class="comment">// The input receiver interface, which just switches light management strategy</span>
    <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent &amp; event)
    {
        <span class="keywordtype">bool</span> handled = <span class="keyword">false</span>;

        <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp; event.KeyInput.PressedDown)
        {
            handled = <span class="keyword">true</span>;
            <span class="keywordflow">switch</span>(event.KeyInput.Key)
            {
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a61ec605d669b598d2e7106981a326fde">irr::KEY_KEY_1</a>:
                RequestedMode = NO_MANAGEMENT;
                <span class="keywordflow">break</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3aa7574bf313b5c29547f01c36f0a4a4f8">irr::KEY_KEY_2</a>:
                RequestedMode = LIGHTS_NEAREST_NODE;
                <span class="keywordflow">break</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a577dcff3b86e6dd45f70d8c691dd3c91">irr::KEY_KEY_3</a>:
                RequestedMode = LIGHTS_IN_ZONE;
                <span class="keywordflow">break</span>;
            <span class="keywordflow">default</span>:
                handled = <span class="keyword">false</span>;
                <span class="keywordflow">break</span>;
            }

            <span class="keywordflow">if</span>(NO_MANAGEMENT == RequestedMode)
                SceneManager-&gt;setLightManager(0); <span class="comment">// Show that it&#39;s safe to register the light manager</span>
            <span class="keywordflow">else</span>
                SceneManager-&gt;setLightManager(<span class="keyword">this</span>);
        }

        <span class="keywordflow">return</span> handled;
    }


    <span class="comment">// This is called before the first scene node is rendered.</span>
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnPreRender(core::array&lt;scene::ISceneNode*&gt; &amp; lightList)
    {
        <span class="comment">// Update the mode; changing it here ensures that it&#39;s consistent throughout a render</span>
        Mode = RequestedMode;

        <span class="comment">// Store the light list. I am free to alter this list until the end of OnPostRender().</span>
        SceneLightList = &amp;lightList;
    }

    <span class="comment">// Called after the last scene node is rendered.</span>
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnPostRender()
    {
        <span class="comment">// Since light management might be switched off in the event handler, we&#39;ll turn all</span>
        <span class="comment">// lights on to ensure that they are in a consistent state. You wouldn&#39;t normally have</span>
        <span class="comment">// to do this when using a light manager, since you&#39;d continue to do light management</span>
        <span class="comment">// yourself.</span>
        <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); i++)
            (*SceneLightList)[i]-&gt;setVisible(<span class="keyword">true</span>);
    }

    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRenderPassPreRender(<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> renderPass)
    {
        <span class="comment">// I don&#39;t have to do anything here except remember which render pass I am in.</span>
        CurrentRenderPass = renderPass;
    }

    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRenderPassPostRender(<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> renderPass)
    {
        <span class="comment">// I only want solid nodes to be lit, so after the solid pass, turn all lights off.</span>
        <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fad058b020ab42ad745cc03fe379148e1f" title="Solid scene nodes or special scene nodes without materials.">scene::ESNRP_SOLID</a> == renderPass)
        {
            <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); ++i)
                (*SceneLightList)[i]-&gt;setVisible(<span class="keyword">false</span>);
        }
    }

    <span class="comment">// This is called before the specified scene node is rendered</span>
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnNodePreRender(scene::ISceneNode* node)
    {
        CurrentSceneNode = node;

        <span class="comment">// This light manager only considers solid objects, but you are free to manipulate</span>
        <span class="comment">// lights during any phase, depending on your requirements.</span>
        <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fad058b020ab42ad745cc03fe379148e1f" title="Solid scene nodes or special scene nodes without materials.">scene::ESNRP_SOLID</a> != CurrentRenderPass)
            <span class="keywordflow">return</span>;

        <span class="comment">// And in fact for this example, I only want to consider lighting for cube scene</span>
        <span class="comment">// nodes.  You will probably want to deal with lighting for (at least) mesh /</span>
        <span class="comment">// animated mesh scene nodes as well.</span>
        <span class="keywordflow">if</span> (node-&gt;getType() != <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda44d66f5c284aed4d0698d6854b6a72e3" title="simple cube scene node">scene::ESNT_CUBE</a>)
            <span class="keywordflow">return</span>;

        <span class="keywordflow">if</span> (LIGHTS_NEAREST_NODE == Mode)
        {
            <span class="comment">// This is a naive implementation that prioritises every light in the scene</span>
            <span class="comment">// by its proximity to the node being rendered.  This produces some flickering</span>
            <span class="comment">// when lights orbit closer to a cube than its &#39;zone&#39; lights.</span>
            <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a> nodePosition = node-&gt;getAbsolutePosition();

            <span class="comment">// Sort the light list by prioritising them based on their distance from the node</span>
            <span class="comment">// that&#39;s about to be rendered.</span>
            array&lt;LightDistanceElement&gt; sortingArray;
            sortingArray.reallocate(SceneLightList-&gt;size());

            <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i;
            <span class="keywordflow">for</span>(i = 0; i &lt; SceneLightList-&gt;size(); ++i)
            {
                scene::ISceneNode* lightNode = (*SceneLightList)[i];
                <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> distance = lightNode-&gt;getAbsolutePosition().getDistanceFromSQ(nodePosition);
                sortingArray.push_back(LightDistanceElement(lightNode, distance));
            }

            sortingArray.sort();

            <span class="comment">// The list is now sorted by proximity to the node.</span>
            <span class="comment">// Turn on the three nearest lights, and turn the others off.</span>
            <span class="keywordflow">for</span>(i = 0; i &lt; sortingArray.size(); ++i)
                sortingArray[i].node-&gt;setVisible(i &lt; 3);
        }
        <span class="keywordflow">else</span> <span class="keywordflow">if</span>(LIGHTS_IN_ZONE == Mode)
        {
            <span class="comment">// Empty scene nodes are used to represent &#39;zones&#39;.  For each solid mesh that</span>
            <span class="comment">// is being rendered, turn off all lights, then find its &#39;zone&#39; parent, and turn</span>
            <span class="comment">// on all lights that are found under that node in the scene graph.</span>
            <span class="comment">// This is a general purpose algorithm that doesn&#39;t use any special</span>
            <span class="comment">// knowledge of how this particular scene graph is organised.</span>
            <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); ++i)
            {
                <span class="keywordflow">if</span> ((*SceneLightList)[i]-&gt;getType() != <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda73c87b4a418b0b7dc9d441cdf45f51e3" title="Light Scene Node.">scene::ESNT_LIGHT</a>)
                    <span class="keywordflow">continue</span>;
                scene::ILightSceneNode* lightNode = <span class="keyword">static_cast&lt;</span>scene::ILightSceneNode*<span class="keyword">&gt;</span>((*SceneLightList)[i]);
                video::SLight &amp; lightData = lightNode-&gt;getLightData();

                <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1video.html#aaf0e02f6f83cc35cf9e764bf18400d39a46a64f42740c097ee15d5c3a87961788" title="directional light, coming from a direction from an infinite distance">video::ELT_DIRECTIONAL</a> != lightData.Type)
                    lightNode-&gt;setVisible(<span class="keyword">false</span>);
            }

            scene::ISceneNode * parentZone = findZone(node);
            <span class="keywordflow">if</span> (parentZone)
                turnOnZoneLights(parentZone);
        }
    }

    <span class="comment">// Called after the specified scene node is rendered</span>
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnNodePostRender(scene::ISceneNode* node)
    {
        <span class="comment">// I don&#39;t need to do any light management after individual node rendering.</span>
    }

<span class="keyword">private</span>:

    <span class="comment">// Find the empty scene node that is the parent of the specified node</span>
    scene::ISceneNode * findZone(scene::ISceneNode * node)
    {
        <span class="keywordflow">if</span> (!node)
            <span class="keywordflow">return</span> 0;

        <span class="keywordflow">if</span> (node-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda977d9500eeb4d4f23e5676a312367f57" title="Empty Scene Node.">scene::ESNT_EMPTY</a>)
            <span class="keywordflow">return</span> node;

        <span class="keywordflow">return</span> findZone(node-&gt;getParent());
    }

    <span class="comment">// Turn on all lights that are children (directly or indirectly) of the</span>
    <span class="comment">// specified scene node.</span>
    <span class="keywordtype">void</span> turnOnZoneLights(scene::ISceneNode * node)
    {
        core::list&lt;scene::ISceneNode*&gt; <span class="keyword">const</span> &amp; children = node-&gt;getChildren();
        <span class="keywordflow">for</span> (core::list&lt;scene::ISceneNode*&gt;::ConstIterator child = children.begin();
            child != children.end(); ++child)
        {
            <span class="keywordflow">if</span> ((*child)-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda73c87b4a418b0b7dc9d441cdf45f51e3" title="Light Scene Node.">scene::ESNT_LIGHT</a>)
                (*child)-&gt;setVisible(<span class="keyword">true</span>);
            <span class="keywordflow">else</span> <span class="comment">// Assume that lights don&#39;t have any children that are also lights</span>
                turnOnZoneLights(*child);
        }
    }


    <span class="comment">// A utility class to aid in sorting scene nodes into a distance order</span>
    <span class="keyword">class </span>LightDistanceElement
    {
    <span class="keyword">public</span>:
        LightDistanceElement() {};

        LightDistanceElement(scene::ISceneNode* n, <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> d)
            : node(n), distance(d) { }

        scene::ISceneNode* node;
        <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> distance;

        <span class="comment">// Lower distance elements are sorted to the start of the array</span>
        <span class="keywordtype">bool</span> operator &lt; (<span class="keyword">const</span> LightDistanceElement&amp; other)<span class="keyword"> const</span>
<span class="keyword">        </span>{
            <span class="keywordflow">return</span> (distance &lt; other.distance);
        }
    };
};
</pre></div><div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argumentCount, <span class="keywordtype">char</span> * argumentValues[])
{
    <span class="comment">// ask user for driver</span>
    <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType=driverChoiceConsole();
    <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>)
        <span class="keywordflow">return</span> 1;

    IrrlichtDevice *device = <a class="code" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice</a>(driverType,
            dimension2d&lt;u32&gt;(640, 480), 32);

    <span class="keywordflow">if</span>(!device)
        <span class="keywordflow">return</span> -1;

    <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <span class="keyword">const</span> lightRadius = 60.f; <span class="comment">// Enough to reach the far side of each &#39;zone&#39;</span>

    video::IVideoDriver* driver = device-&gt;getVideoDriver();
    scene::ISceneManager* smgr = device-&gt;getSceneManager();
    gui::IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();

    gui::IGUISkin* skin = guienv-&gt;getSkin();
    <span class="keywordflow">if</span> (skin)
    {
        skin-&gt;setColor(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aa03e6e93fa9356e9d8d743e6928111185" title="Text on a button.">gui::EGDC_BUTTON_TEXT</a>, video::SColor(255, 255, 255, 255));
        gui::IGUIFont* font = guienv-&gt;getFont(<span class="stringliteral">&quot;../../media/fontlucida.png&quot;</span>);
        <span class="keywordflow">if</span>(font)
            skin-&gt;setFont(font);
    }

    guienv-&gt;addStaticText(L<span class="stringliteral">&quot;1 - No light management&quot;</span>, core::rect&lt;s32&gt;(10,10,200,30));
    guienv-&gt;addStaticText(L<span class="stringliteral">&quot;2 - Closest 3 lights&quot;</span>, core::rect&lt;s32&gt;(10,30,200,50));
    guienv-&gt;addStaticText(L<span class="stringliteral">&quot;3 - Lights in zone&quot;</span>, core::rect&lt;s32&gt;(10,50,200,70));
</pre></div><p>Add several "zones". You could use this technique to light individual rooms, for example. </p>
<div class="fragment"><pre class="fragment">    <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> zoneX = -100.f; zoneX &lt;= 100.f; zoneX += 50.f)
        <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> zoneY = -60.f; zoneY &lt;= 60.f; zoneY += 60.f)
        {
            <span class="comment">// Start with an empty scene node, which we will use to represent a zone.</span>
            scene::ISceneNode * zoneRoot = smgr-&gt;addEmptySceneNode();
            zoneRoot-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(zoneX, zoneY, 0));

            <span class="comment">// Each zone contains a rotating cube</span>
            scene::IMeshSceneNode * node = smgr-&gt;addCubeSceneNode(15, zoneRoot);
            scene::ISceneNodeAnimator * rotation = smgr-&gt;createRotationAnimator(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0.25f, 0.5f, 0.75f));
            node-&gt;addAnimator(rotation);
            rotation-&gt;drop();

            <span class="comment">// And each cube has three lights attached to it.  The lights are attached to billboards so</span>
            <span class="comment">// that we can see where they are.  The billboards are attached to the cube, so that the</span>
            <span class="comment">// lights are indirect descendents of the same empty scene node as the cube.</span>
            scene::IBillboardSceneNode * billboard = smgr-&gt;addBillboardSceneNode(node);
            billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, -14, 30));
            billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
            billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
            billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
            smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(1, 0, 0), lightRadius);

            billboard = smgr-&gt;addBillboardSceneNode(node);
            billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(-21, -14, -21));
            billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
            billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
            billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
            smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(0, 1, 0), lightRadius);

            billboard = smgr-&gt;addBillboardSceneNode(node);
            billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(21, -14, -21));
            billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
            billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
            billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
            smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(0, 0, 1), lightRadius);

            <span class="comment">// Each cube also has a smaller cube rotating around it, to show that the cubes are being</span>
            <span class="comment">// lit by the lights in their &#39;zone&#39;, not just lights that are their direct children.</span>
            node = smgr-&gt;addCubeSceneNode(5, node);
            node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 21, 0));
        }

    smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,-130), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,0));

    CMyLightManager * myLightManager = <span class="keyword">new</span> CMyLightManager(smgr);
    smgr-&gt;setLightManager(0); <span class="comment">// This is the default: we won&#39;t do light management until told to do it.</span>
    device-&gt;setEventReceiver(myLightManager);

    <span class="keywordtype">int</span> lastFps = -1;

    <span class="keywordflow">while</span>(device-&gt;run())
    {
        driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(255,100,101,140));
        smgr-&gt;drawAll();
        guienv-&gt;drawAll();
        driver-&gt;endScene();

        <span class="keywordtype">int</span> fps = driver-&gt;getFPS();
        <span class="keywordflow">if</span>(fps != lastFps)
        {
            lastFps = fps;
            <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">&quot;Managed Lights [&quot;</span>;
            str += driver-&gt;getName();
            str += <span class="stringliteral">&quot;] FPS:&quot;</span>;
            str += fps;
            device-&gt;setWindowCaption(str.c_str());
        }
    }

    myLightManager-&gt;drop(); <span class="comment">// Drop my implicit reference</span>
    device-&gt;drop();
    <span class="keywordflow">return</span> 0;
}
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Tue Jan 19 2016 16:08:47 for Irrlicht 3D Engine by
<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
